package com.sh.data.engine.application.model.request.integration;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * @author : changkong
 * @date : 2022/3/10
 */
@Data
@Schema(title = "预览接口请求参数")
@NoArgsConstructor
@AllArgsConstructor
public class PreviewExpressRequest {

    @NotNull
    @Schema(description = "接口返回的json", requiredMode = Schema.RequiredMode.REQUIRED)
    private String responseRawJson;
    // 要解析的jsonPath表达式列表

    @Valid
    @Schema(description = "用户输入的jsonpath 映射")
    private List<ExpressionParam> expressionParamList;

    // js脚本
    @Schema(description = "js脚本")
    private String jsScript;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ExpressionParam {
        // 用户填写的名称
        @NotNull
        @Pattern(regexp = "^[_a-zA-Z0-9]{2,32}$", message = "参数名称长度在2-32之间, 仅支持英文字母数字下划线")
        @Schema(description = "用户填写的参数名", required = true)
        private String name;

        // jsonPath表达式
        @NotNull
        @Schema(description = "用户填写的jsonpath表达式", required = true)
        private String expression;

        // 层级关系
        @NotNull
        @Range(min = 0, max = 1, message = "层级关系支持0,1")
        @Schema(description = "用户选择的层级关系", required = true)
        private Integer relationship;
    }
}
